//
//  HELStatisticVC.m
//  HandheldELearn
//
//  Created by 陈武琦 on 16/7/13.
//  Copyright © 2016年 陈武琦. All rights reserved.
//
#import "HELMeetingInfo.h"
#import "HELMeetingInfoCell.h"
#import "HELWebViewController.h"
#import "HELSuperTableView.h"
#import "Masonry.h"

static NSString *cellID = @"HELMeetingInfoCellID";
@interface HELMeetingInfo ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic, strong) HELMeetingInfoCell *cell;
//上拉加载的页面
@property (nonatomic, assign) NSInteger page;

@end

@implementation HELMeetingInfo

- (void)viewDidLoad {
    [super viewDidLoad];
    [self titleView:@"通知消息"];
    
    
    self.tableView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
    [self.view addSubview:self.tableView];
    self.tableView.descriptionText = @"没有通知~";
    [self.tableView registerNib:[UINib nibWithNibName:@"HELMeetingInfoCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"HELMeetingInfoCell"];
 
    weakSelf_define;
    // 添加下拉刷新头部控件
    [self.tableView wsj_HeaderRefreshBlock:^{
        //请求加载数据
        weakSelf.page = 1;
        [weakSelf requestData];
    }];

    [self.tableView addLegendFooterWithRefreshingBlock:^{
        weakSelf.page++;
        //请求加载数据
        [weakSelf requestData];
    }];
    self.page = 1;
    [self requestData];
}

- (void)requestData {
    
    
    self.tableView.loading = YES;
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.tableView.loading = NO;
        [self.tableView.header endRefreshing];
        [self.tableView.footer endRefreshing];
    });
    
//    HELUserInfoM *userInfo = [HELAppManager userInfo];
//    if (!userInfo.userId) {
//        cwqAlertMessage(@"用户id获取失败");
//        return;
//    }
//    self.tableView.loading = YES;
//    NSDictionary *param = @{@"pageSize":@20, @"currentPage":@(self.page), @"userId":userInfo.userId};
//       defineWeakSelf;
//    [[HELNetworkManager sharedMg] POST:helMeetingUrl parameters:param success:^(id responseObject) {
//        
//        if (responseObject[@"exception"]) {
//            cwqHudRequestError(responseObject[@"exception"]);
//        }else {
//            NSMutableArray *arr = [NSMutableArray array];
//            for (NSDictionary *dict in responseObject[@"rows"]) {
//                HELMeetingModel *model = [HELMeetingModel mj_objectWithKeyValues:dict];
//                [arr addObject:model];
//            }
//            //判断是上拉刷新？  还是下拉加载？
//            if (weakSelf.page > 1) {
//                NSMutableArray *muArr = [weakSelf.dataArray mutableCopy];
//                
//                [muArr addObjectsFromArray:arr];
//                weakSelf.dataArray = [muArr copy];
//                if (weakSelf.page == [responseObject[@"pages"] integerValue]) {
//                    weakSelf.tableView.footer.hidden = YES;
//                }
//                [weakSelf.tableView.footer endRefreshing];
//            }else {
//                
//                if (weakSelf.page == [responseObject[@"pages"] integerValue]) {
//                    weakSelf.tableView.footer.hidden = YES;
//                }else {
//                    weakSelf.tableView.footer.hidden = NO;
//                }
//                weakSelf.dataArray = arr;
//                [weakSelf.tableView.header endRefreshing];
//            }
//            if (weakSelf.dataArray.count<=0) {
//                weakSelf.tableView.loading = NO;
//            }
//
//            [weakSelf.tableView reloadData];
//            
//        }
//    } failure:^(NSString *err) {
//        if (weakSelf.page > 1) {
//            //上拉
//            [weakSelf.tableView.footer endRefreshing];
//            weakSelf.page -= 1;
//        }else {
//            //下拉
//            [weakSelf.tableView.header endRefreshing];
//            if (weakSelf.dataArray.count<=0) {
//                self.tableView.footer.hidden = YES;
//            }else {
//                
//                self.tableView.footer.hidden = NO;
//            }
//        }
//        cwqHudRequestError(err);
//        if (weakSelf.dataArray.count<=0) {
//            weakSelf.tableView.loading = NO;
//        }
//
//    }];
//    
    
}

#pragma mark - <UITableViewData and UITableDelegate>
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataArray.count;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    
    
   
    
    return 86;
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    HELMeetingInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HELMeetingInfoCell" forIndexPath:indexPath];
  

    HELMeetingModel *model = self.dataArray[indexPath.row];
    [cell setModel:model];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell setNeedsUpdateConstraints];
    [cell updateConstraintsIfNeeded];
    return cell;
    
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//    HELUserInfoM *userInfo = [HELAppManager userInfo];
//    if (!userInfo.userId) {
//        cwqAlertMessage(@"用户id获取失败");
//        return;
//    }

    HELMeetingModel *model = self.dataArray[indexPath.row];
    HELWebViewController *webVC = [[HELWebViewController alloc] init];
    NSString *url = [[[HELNetworkManager sharedMg] getBaseUrl] stringByAppendingString:helMeetingDeatailUrl];
//    url = [url stringByAppendingFormat:@"?noticeId=%@&userId=%@",model.id,userInfo.userId];
    webVC.url = [NSURL URLWithString:url];
    [self.navigationController pushViewController:webVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
